package dao;

import static org.junit.Assert.*;

import java.sql.SQLException;
import java.sql.Date;
import java.util.List;

import modele.Session;
import dao.SessionDAO;

import org.junit.Test;

public class TestSessionDAO extends AgriotesDbTestCase {

	@Test
	public void testInserer() throws SQLException {
		Session s = new Session(40, 2, Date.valueOf("2010-11-03"),
				Date.valueOf("2011-11-03"), 30, 200,
				Date.valueOf("2012-11-03"), Date.valueOf("2012-12-03"));
		Session s2 = null;
		SessionDAO dao = new SessionDAO();
		dao.inserer(s);
	}

	@Test
	public void testSupprimer() throws SQLException {
		SessionDAO dao = new SessionDAO();
		dao.supprimer(26);
		assertNull("Non supprimé", dao.lireParId(26));
	}

	@Test
	public void testlireParId() throws SQLException {
		SessionDAO dao = new SessionDAO();
		Session expected = new Session(1, 4, Date.valueOf("2014-03-03"),
				Date.valueOf("2014-06-01"), 23, 515,
				Date.valueOf("2013-12-03"), Date.valueOf("2014-02-01"));
		Session result = dao.lireParId(1);
		assertEquals(expected, result);
	}

	@Test
	public void testSessionsFutures() throws SQLException {
		SessionDAO dao = new SessionDAO();
		// A faire absolument avec un parametre date !!!
		List<Session> result = dao.listerSessionsFutures(Date
				.valueOf("2014-03-03"));
		assertEquals(7, result.size());
		Session expected = new Session(1, 4, Date.valueOf("2014-03-03"),
				Date.valueOf("2014-06-01"), 23, 515.0,
				Date.valueOf("2013-12-03"), Date.valueOf("2014-02-01"));
		assertEquals(expected, result.get(0));
	}
}
